import os

import pygame
from PIL import Image, ImageSequence
from function import *
from plant import *
from interface import RandomSun

# 初始化pygame
pygame.init()

# 创建pygame窗口
width, height = 1200, 600
screen = pygame.display.set_mode((width, height))
back_image = pg.image.load('images\\interface\\background1.jpg')
clock = pg.time.Clock()
sun = RandomSun(screen, [])

grade = np.full((5, 9), None)
for row in range(grade.shape[0]):
    for column in range(grade.shape[1]):
        grade[row][column] = SunFlower(screen, row, column, sun)
# 播放GIF
running = True
while running:
    for event in pygame.event.get():
        if event.type == pg.QUIT:
            running = False
        elif event.type == pg.MOUSEBUTTONDOWN:
            if event.button == 1:
                click = event.pos
                onclick(grade, click)
                sun.onclick(click)

    screen.blit(back_image, (0, 0))
    update(grade)
    sun.update()
    clock.tick(10)
    pg.display.flip()

# 退出pygame
pygame.quit()
